package com.boot.interceptor;

import com.alibaba.fastjson.JSONObject;
import com.boot.entity.UserDTO;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author Chunsheng.Zhang
 * @date 2021/4/1 16:24
 * @description : TODO
 */

public class AuthenticationInterceptor extends HandlerInterceptorAdapter {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {


        //通过request获取请求体中所有对象
        BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
        StringBuilder responseStrBuilder = new StringBuilder();
        String inputStr;
        while ((inputStr = streamReader.readLine()) != null) {
            responseStrBuilder.append(inputStr);
        }


        UserDTO userDTO = JSONObject.parseObject(responseStrBuilder.toString(), UserDTO.class);

        System.out.println(userDTO.getRealName()+"**************");




        return  false;
    }


}
